package redis;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import redis.clients.jedis.Jedis;

public class TestKey {
	static Jedis jedis = null;

    static {
        jedis = new Jedis("192.168.79.131", 6379);//redis服务器地址与端口号
        jedis.auth("211125");
    }
    
    // 测试Java做为客户端连接redis
    public static void main(String[] args) {
    	System.out.println("服务启动..."+jedis.ping());
    	jedis.flushDB();
    }
    
    // 7.5.2 操作键
    @Test
    public void setTest() {
    	String result = jedis.set("userid", "202111110311");
    	System.out.println(result);
    }

    @Test
    public void getTest() {
        String result = jedis.get("userid");
        System.out.println(result);
    }

    @Test
    public void keysAll(){
        Set<String> keys = jedis.keys("*");
        for (String key : keys) {
            System.out.println(key);
        }
    }
    
    @Test
    public void msetTest() {
    	String manykey = jedis.mset("sclass1", "rj211","sclass2", "rj212");
    	System.out.println(manykey);
    }
    
    @Test
    public void keysTest() {
    	Set<String> keys = jedis.keys("*");
    	System.out.println(keys);
    }
    
    @Test
    public void mgetTest() {
    	List<String> values = jedis.mget("sclass1","sclass2");
    	System.out.println(values);
    }

    @Test
    public void expireTest() {
        long values = jedis.expire("userid",50L);
        System.out.println(values);
    }

    @Test
    public void ttlTest() {
        long values = jedis.ttl("userid");
        System.out.println(values);
    }
    
    @Test
    public void existTest() {
    	Boolean result1 = jedis.exists("userid");
    	System.out.println(result1+"-----------------");
    }
    @Test
    public void typeTest() {
        String useridType = jedis.type("userid");
        System.out.println(useridType+"-----------------");
    }
    
    @Test
    public void renameTest() {
    	String rename = jedis.rename("sclass", "sclass0");
    	System.out.println(rename);
    }
    
    @Test
    public void delTest() {
    	Long result = jedis.del("sclass0");
    	System.out.println(result);
    }


    /**
     *
     */

    @Test
    public void msetTest1() {
        String mset = jedis.mset("course1", "database", "course2", "data structure", "course3", "Java Web");
        System.out.println(mset);
    }

    @Test
    public void mgetTest1() {
        List<String> courses = jedis.mget("course1", "course2", "course3");
        for (String cours : courses) {
            System.out.println(cours);
        }
    }
    @Test
    public void delTest1() {
        Long result = jedis.del("course1");
        System.out.println(result);
    }
}
